// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.ai.states;

import fmod.fmod.FMODManager;
import zombie.ai.State;
import zombie.audio.parameters.ParameterCharacterMovementSpeed;
import zombie.characters.IsoGameCharacter;
import zombie.characters.IsoPlayer;
import zombie.core.skinnedmodel.advancedanimation.AnimEvent;
import zombie.iso.IsoDirections;

public final class CollideWithWallState extends State {
    private static final CollideWithWallState _instance = new CollideWithWallState();

    public static CollideWithWallState instance() {
        return _instance;
    }

    @Override
    public void enter(IsoGameCharacter owner) {
        owner.setIgnoreMovement(true);
        if (owner instanceof IsoPlayer) {
            ((IsoPlayer)owner).setIsAiming(false);
        }

        if (owner.isCollidedN()) {
            owner.setDir(IsoDirections.N);
        }

        if (owner.isCollidedS()) {
            owner.setDir(IsoDirections.S);
        }

        if (owner.isCollidedE()) {
            owner.setDir(IsoDirections.E);
        }

        if (owner.isCollidedW()) {
            owner.setDir(IsoDirections.W);
        }

        owner.setCollideType("wall");
    }

    @Override
    public void execute(IsoGameCharacter owner) {
        owner.setLastCollideTime(70.0F);
    }

    @Override
    public void exit(IsoGameCharacter owner) {
        owner.setCollideType(null);
        owner.setIgnoreMovement(false);
    }

    @Override
    public void animEvent(IsoGameCharacter owner, AnimEvent event) {
        if ("PlayCollideSound".equalsIgnoreCase(event.m_EventName)) {
            long _long = owner.playSound(event.m_ParameterValue);
            ParameterCharacterMovementSpeed parameterCharacterMovementSpeed = ((IsoPlayer)owner).getParameterCharacterMovementSpeed();
            owner.getEmitter()
                .setParameterValue(
                    _long, parameterCharacterMovementSpeed.getParameterDescription(), (float)ParameterCharacterMovementSpeed.MovementType.Sprint.label
                );
            owner.getEmitter().setParameterValue(_long, FMODManager.instance.getParameterDescription("TripObstacleType"), 7.0F);
        }
    }
}
